{% extends "base.html" %}
{% load services %}

{%block head %}
    <link rel="stylesheet" type="text/css"
        href="/railroad-static/css/downtime.css" />
    <script language="javascript" type="text/javascript"
        src="{% url js 'js/downtime.js' %}"></script>
{% endblock %}

{% block header %}
<h1>Downtime</h1>
{% endblock %}

{% block content %}
    {% if downtime %}
        <div id="downtimegraph">
            {{ json_downtime }}
        </div>
        {% for dt in downtime %}
            {% cycle '<div class="downtimerow">' '</div>' as even %}
            <div class="downtime" id="{{dt.id}}">
                {% if dt.expr %}
                    <h3>{{ dt.expr }}</h3>
                {% else %}
                    <h3>{{ dt.comment }}</h3>
                {% endif %}
                <ul>
                    <li>{{ dt.start_time|pretty_daterange:dt.end_time }}</li>
                    <li>Comment: "{{dt.comment}}"</li>
                    <li>Scheduled by: {{dt.author}}</li>
                    {% if dt.key %}
                        <li>Cancellation key: <a href="#" class="canceldowntime">{{ dt.key }}</a></li>
                    {% endif %}
                    <li class="twirler">
                        <span class="target">Affected Services:</span>
                        <ul>
                            {% regroup dt.hosts_services by service as services %}
                            {% for service in services %}
                                <li class="twirler">
                                    <span class="target">{{service.grouper}}</span>
                                    <ul>
                                        {% for host in service.list %}
                                            <li>{{host.host}}</li>
                                        {% endfor %}
                                    </ul>
                                </li>
                            {% endfor %}
                        </ul>
                    </li>
                    <li class="twirler">
                        <span class="target">Affected Hosts:</span>
                        <ul>
                            {% regroup dt.hosts_services by host as hosts %}
                            {% for host in hosts %}
                                <li class="twirler">
                                    <span class="target">{{host.grouper}}</span>
                                    <ul>
                                        {% for service in host.list %}
                                            <li>{{service.service}}</li>
                                        {% endfor %}
                                    </ul>
                                </li>
                            {% endfor %}
                        </ul>
                    </li>
                </ul>
            </div>
            {% cycle '<div class="downtimerow">' '</div>' as even %}
        {% endfor %}
    {% else %}
        <p>There are no scheduled downtimes.</p>
    {% endif %}
{% endblock %}
